package com.eleadmin.order.service.impl;

import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.common.system.entity.User;
//import com.eleadmin.order.mapper.ApplyCustomsMapper;
import com.eleadmin.order.biz.CustomerBiz33;
import com.eleadmin.order.entity.ApplyCustoms;
import com.eleadmin.order.entity.Customer23123;
import com.eleadmin.order.service.ApplyCustomsService;
import org.springframework.stereotype.Service;
import com.eleadmin.order.biz.ApplyCustomsBiz;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

/**
 * 报关服务实现类
 * @author : Doman
 * @date : 2023-05-06 10:49:33
 * @version ：1.0
 */
@Service
public class ApplyCustomsServiceImpl /*extends ServiceImpl<ApplyCustomsMapper, ApplyCustoms> */implements ApplyCustomsService {

    @Autowired
    private ApplyCustomsBiz applyCustomsBiz;
    @Autowired
    private CustomerBiz33 customerBiz;

    @Override
    public JsonResult list(PageResult2<T> page, ApplyCustoms applyCustoms, User loginUser)  throws Exception{
        return applyCustomsBiz.list(page,applyCustoms,loginUser);
    }

    @Override
    public JsonResult list(ApplyCustoms applyCustoms, User loginUser) {
        return JsonResult.ok().setData(applyCustomsBiz.list(applyCustoms,loginUser));
    }

    @Override
    public JsonResult getById(String id) {
        return JsonResult.ok().setData(applyCustomsBiz.getById(id));
    }

    @Transactional
    @Override
    public JsonResult save(ApplyCustoms applyCustoms, User loginUser) {
        Customer23123 customer = customerBiz.getById(applyCustoms.getCustomerId()+"");
        applyCustoms.setSalesmanid(customer.getSalesmanid());
        applyCustoms.setSalesman(customer.getSalesman());
        applyCustoms.setOperaterid(customer.getOperaterid());
        applyCustoms.setOperater(customer.getOperater());
        if (applyCustomsBiz.save(applyCustoms, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(ApplyCustoms applyCustoms, User loginUser) {
        if (applyCustomsBiz.update(applyCustoms, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(String id, User loginUser) {
        if (applyCustomsBiz.remove(id, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
